package com.sip.stream.utils;

import android.graphics.drawable.Drawable;
import android.widget.ImageView;
import android.widget.TextView;
import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;

public class RxViewBinder {
    public static void bind(Observable<String> observable, final TextView textView, final CompositeDisposable compositeDisposable) {
        observable.observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<String>() {
            @Override
            public void onComplete() {
            }

            @Override
            public void onError(Throwable th) {
            }

            @Override
            public void onSubscribe(Disposable disposable) {
                compositeDisposable.add(disposable);
            }

            @Override
            public void onNext(String str) {
                textView.setText(str);
            }
        });
    }

    public static void bindTextViewColor(Observable<Integer> observable, final TextView textView, final CompositeDisposable compositeDisposable) {
        observable.observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<Integer>() {
            @Override
            public void onComplete() {
            }

            @Override
            public void onError(Throwable th) {
            }

            @Override
            public void onSubscribe(Disposable disposable) {
                compositeDisposable.add(disposable);
            }

            @Override
            public void onNext(Integer num) {
                textView.setTextColor(num.intValue());
            }
        });
    }

    public static void bindDrawable(Observable<Drawable> observable, final ImageView imageView, final CompositeDisposable compositeDisposable) {
        observable.observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<Drawable>() {
            @Override
            public void onComplete() {
            }

            @Override
            public void onError(Throwable th) {
            }

            @Override
            public void onSubscribe(Disposable disposable) {
                compositeDisposable.add(disposable);
            }

            @Override
            public void onNext(Drawable drawable) {
                imageView.setImageDrawable(drawable);
            }
        });
    }
}
